<?php

namespace App\Admin\Actions\Post;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use App\Models\CompanyJob;

class ChangeJobToDelete extends RowAction
{
    public $name = '删除';

    public function handle(Model $model)
    {
        $status = $model->job_status;
        if (!in_array($status, [-1, 0])) {
            return $this->response()->error('不可执行该操作！')->refresh();
        }

        $id = $model->id;
        $res = CompanyJob::where('id', $id)->update(['job_status' => -2]);
        if ($res) {
            return $this->response()->success('操作成功！')->refresh();
        } else {
            return $this->response()->error('操作失败！')->refresh();
        }
    }

    public function dialog()
    {
        $this->confirm('确定删除吗？');
    }

}